<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * returnJson 方法
     * @param int $status 0成功 1失败
     * @param null $data 结果
     * @param null $message 消息提示
     * @return bool
     */
    protected function returnJson($status = 0,$data = null,$message = null){
        $data = [
            "status" => $status,
            "data" => $data,
            "message" => $message ?? 'success'
        ];
        return response()->json($data);
    }



    /**
     * 状态数字转换成文字
     * @param array $data 列表数据
     * @param array $arr 转化的数组
     * @return mixed
     */
    protected function stateToWord(&$data, $arr = []){
        foreach ($data as $key => &$row) {
            foreach ($arr as $k => $val) {
                if (isset($row[$k]) && isset($val[$row[$k]])) {
                    $text = $k . '_text';
                    $row[$text] = $val[$row[$k]];
                }
            }
        }
        return $data;
    }


















}
